<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var consumeVerifyDataGrid;
    $(function() {
        consumeVerifyDataGrid = $('#consumeVerifyDataGrid').datagrid({
            url : '${path }/consumeVerify/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                field : 'consumption_upload_id',
                title : '消费上传id',
                width : 40,
                hidden : true
            } ] ],
            columns : [ [ {
                field : 'invoice_no',
                title : '发票号码',
                width : 150
            },{
                field : 'consumption_name',
                title : '消费人员',
                width : 110
            },{
                field : 'amount',
                title : '消费金额',
                width : 80
            },{
                field : 'province',
                title : '省',
                width : 120
            },{
                field : 'city',
                title : '市',
                width : 70
            },{
                field : 'area',
                title : '区',
                width : 70
            },{
                field: 'status',
                title: '审核状态',
                width: '80',
                sortable:true,
                formatter : function(value, row, index){
                    switch (value){
                        case 2:
                            return '未通过';
                        case 1:
                            return '通过';
                        case 0:
                            return '待审';
                    }
                }
            },{
                field : 'action',
                title : '操作',
                width : 180,
                formatter : function(value, row, index) {
                    var str = '';

                    if(row.status == 0){
                        str += $.formatString('<a href="javascript:void(0)" class="consumeVerify-easyui-linkbutton-pass" ' +'data-options="plain:true,iconCls:\'fi-pencil icon-blue\'"' +
                            ' onclick="consumeVerifyFun(\'{0}\',\'{1}\');" >通过审核</a>', row.consumption_upload_id,1);
                        str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                        str += $.formatString('<a href="javascript:void(0)" class="consumeVerify-easyui-linkbutton-refuse" ' +'data-options="plain:true,iconCls:\'fi-x icon-red\'"' +
                            ' onclick="consumeVerifyFun(\'{0}\',\'{1}\');" >不通过</a>', row.consumption_upload_id,2);
                    }else {
                        str += $.formatString('<a href="javascript:void(0)" class="consumeVerify-easyui-linkbutton-pass" ' +'data-options="plain:true,iconCls:\'fi-pencil icon-blue\'"' +
                            ' disabled="disabled">通过审核</a>', row.consumption_upload_id,1);
                        str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                        str += $.formatString('<a href="javascript:void(0)" class="consumeVerify-easyui-linkbutton-refuse" ' +'data-options="plain:true,iconCls:\'fi-x icon-red\'"' +
                            ' disabled="disabled" >不通过</a>', row.consumption_upload_id,2);
                    }
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.consumeVerify-easyui-linkbutton-pass').linkbutton({text:'通过审核'});
                $('.consumeVerify-easyui-linkbutton-refuse').linkbutton({text:'不通过'});
            }
        });
    });


    function consumeVerifyFun(consumption_upload_id,type){

        var showMsg = '是否通过审核?';
        if(type == 2 ){
            showMsg = '确认不通过审核?';
        }

        parent.$.messager.confirm('询问', showMsg , function(b) {
            if (b  ) {
                $.post('${path }/consumeVerify/passVerify', {
                    id : consumption_upload_id
                    ,type:type
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        consumeVerifyDataGrid.datagrid('reload');
                    }else{
                        parent.$.messager.alert('提示', result.msg, 'info');
                        consumeVerifyDataGrid.datagrid('reload');
                    }
                }, 'JSON');
            };
        });
    }
    
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="consumeVerifyDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
